﻿using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Entity
{
    public class DBcount : DbContext
    {

        public DBcount(DbContextOptions<DBcount> opts) : base(opts)
        {

        }

        /// <summary>
        /// 商品分类表
        /// </summary>
        public DbSet<Category> Category { get; set; }

        /// <summary>
        /// 商品SPU表
        /// </summary>
        public DbSet<Product> Product { get; set; }

        /// <summary>
        /// 订单主表
        /// </summary>
        public DbSet<Order> Order { get; set; }

        /// <summary>
        /// 订单明细表
        /// </summary>
        public DbSet<Order_item> MyProperty { get; set; }

        /// <summary>
        /// ⽤户主表
        /// </summary>
        public DbSet<User> User { get; set; }

        /// <summary>
        /// ⽤户信息表
        /// </summary>
        public DbSet<User_profile> User_profile { get; set; }

        /// <summary>
        /// 地址表
        /// </summary>
        public DbSet<Address> Address { get; set; }

        /// <summary>
        /// 仓库表
        /// </summary>
        public DbSet<Warehouse> Warehouses { get; set; }

        /// <summary>
        /// 物流跟踪表
        /// </summary>
        public DbSet<Logistics> Logistics { get; set; }

        /// <summary>
        /// 优惠卷表
        /// </summary>
        public DbSet<Coupon> Coupons { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            User user = new User();
            user.FirstName = "123123";
            user.LastName = "3453";

            modelBuilder.Entity<User>().HasData([

                new User{
                    FirstName="zhangsan",
                    LastName="san",
                    Email="44444444444444"
                },

                new User{

                }
                ]);
        }

        //protected override void OnModelCreating(ModelBuilder modelBuilder)
        //{
        //    modelBuilder.UseCollation("utf8mb4_german2_ci").HasCharSet("utf8mb4");
        //}
    }

    public class DBcountFatory : IDesignTimeDbContextFactory<DBcount>
    {
        public DBcount CreateDbContext(string[] args)
        {
            var optionBulider = new DbContextOptionsBuilder<DBcount>();
            optionBulider.UseMySql(
                "server=localhost;userid=root;password=123456;database=AIYDB;port=3306;",
                new MySqlServerVersion(new Version(8, 0, 41)));

            return new DBcount(optionBulider.Options);
        }




    }
}
